package com.vipheyue.bigbusiness.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vipheyue.bigbusiness.R;
import com.vipheyue.bigbusiness.activity.AppIntroductionActivity;
import com.vipheyue.bigbusiness.activity.EmployeeActivity;
import com.vipheyue.bigbusiness.activity.FavoritesActivity;
import com.vipheyue.bigbusiness.activity.LoginActivity;
import com.vipheyue.bigbusiness.activity.PublishedActivity;
import com.vipheyue.bigbusiness.activity.ReleaseActivity;
import com.vipheyue.bigbusiness.bean.MyUser;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.BmobUser;


public class ReNameFragment3 extends Fragment {
    View view;
    @Bind(R.id.rl_menu_left)
    RelativeLayout rl_menu_left;
    @Bind(R.id.tv_Menu_Title)
    TextView tv_Menu_Title;
    @Bind(R.id.iv_menu_right)
    ImageView iv_menu_right;
    @Bind(R.id.rl_menu_right)
    RelativeLayout rl_menu_right;
    @Bind(R.id.iv_icon1)
    ImageView iv_icon1;
    @Bind(R.id.rl_collect)
    RelativeLayout rl_collect;
    @Bind(R.id.iv_icon2)
    ImageView iv_icon2;
    @Bind(R.id.iv_icon3)
    ImageView iv_icon3;
    @Bind(R.id.rl_collect3)
    RelativeLayout rl_collect3;
    @Bind(R.id.iv_Menu_leftImg)
    ImageView iv_Menu_leftImg;
    @Bind(R.id.tv_Menu_leftTitle)
    TextView tv_Menu_leftTitle;
    @Bind(R.id.iv_menu_rightTitle)
    TextView iv_menu_rightTitle;
    @Bind(R.id.rl_companyIntroduction)
    RelativeLayout rl_companyIntroduction;
    @Bind(R.id.iv_icon22)
    ImageView iv_icon22;
    @Bind(R.id.rl_EmployeeQuery)
    RelativeLayout rl_EmployeeQuery;
    @Bind(R.id.iv_Release_icon)
    ImageView iv_Release_icon;
    @Bind(R.id.rl_Release)
    RelativeLayout rl_Release;
    @Bind(R.id.iv_Published_icon)
    ImageView iv_Published_icon;
    @Bind(R.id.rl_Published)
    RelativeLayout rl_Published;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.rename_fragment3, null);
        ButterKnife.bind(this, view);
        tv_Menu_Title.setText("我的");
        rl_menu_left.setVisibility(View.INVISIBLE);
        initView();
        return view;
    }

    private void initView() {
        if (havePermission()) {
            rl_EmployeeQuery.setVisibility(View.VISIBLE);
            rl_Release.setVisibility(View.VISIBLE);
            rl_Published.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.rl_collect, R.id.rl_collect3, R.id.rl_EmployeeQuery, R.id.rl_companyIntroduction, R.id.rl_Release, R.id.rl_Published})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_collect:
                startActivity(new Intent(getActivity(), FavoritesActivity.class));
                break;
            case R.id.rl_companyIntroduction:
                startActivity(new Intent(getActivity(), AppIntroductionActivity.class));
                break;
            case R.id.rl_collect3:
                BmobUser.logOut(getActivity());   //清除缓存用户对象
                getActivity().finish();
                break;
            case R.id.rl_EmployeeQuery:
                startActivity(new Intent(getActivity(), EmployeeActivity.class));
//                MyUser userInfo = BmobUser.getCurrentUser(getActivity(), MyUser.class);
//                if (userInfo != null) {
//                    startActivity(new Intent(getActivity(), EmployeeActivity.class));
//                } else {
//                    startActivity(new Intent(getActivity(), LoginActivity.class));
//                    getActivity().finish();
//                }
                break;
            case R.id.rl_Release:
                startActivity(new Intent(getActivity(), ReleaseActivity.class));
                break;
            case R.id.rl_Published:
                startActivity(new Intent(getActivity(), PublishedActivity.class));
                break;
        }
    }

    private boolean havePermission() {
        MyUser userInfo = BmobUser.getCurrentUser(getActivity(), MyUser.class);
        if (userInfo == null) {
            startActivity(new Intent(getActivity(), LoginActivity.class));
            getActivity().finish();
            return false;
        } else {
            if (userInfo.getUserType().equals("boss")) {
                return true;
            } else {
                return false;
            }
        }
    }
}
